package com.schooldate.model.action;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.schooldate.base.BaseAction;
import com.schooldate.model.entity.School;
import com.schooldate.util.SimpleJsonFilter;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

/**
 * Created by etund on 2015/3/15 0015.
 */
@Controller
@Scope("prototype")
@SuppressWarnings("all")
public class SchoolAction extends BaseAction<School>{


    private String nearPlaceName;

    /**
     * 根据你的所在地返回你附近的大学
     * @return
     * @throws Exception
     */
    public void getNearSchool() throws Exception{
            if (this.nearPlaceName !=null && !"".equals(this.nearPlaceName) ){
//                this.schools = this.schoolService.getSchoolByPlace(this.nearPlaceName);
                String[]  names = nearPlaceName.split("");
                this.schools = this.schoolService.getBySchoolNames(names);
                object.put("code",1);
                object.put("schools",schools);
                SimpleJsonFilter filter = new SimpleJsonFilter("nearSchool.do");
                result = JSON.toJSONString(object,filter, SerializerFeature.DisableCircularReferenceDetect);
                renderJson(result);
            }else {
                object.put("code",1);
                result = JSON.toJSONString(result);
                renderJson(result);
            }
    }



    public String getNearPlaceName() {
        return nearPlaceName;
    }

    public void setNearPlaceName(String nearPlaceName) {
        this.nearPlaceName = nearPlaceName;
    }
}
